package com.ymatou.livevideo.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.livevideo.parameter.StateChangeInfo;
import com.ymatou.livevideo.parameter.SyncTimMsgCallBackReq;
import com.ymatou.livevideo.parameter.TimChatMessageBody;
import com.ymatou.livevideo.parameter.TimChatMessageContent;
import com.ymatou.livevideo.parameter.TimNotifyBean;
import com.ymatou.livevideo.parameter.TimNotifyReq;
import com.ymatou.livevideo.service.TimNotifyCall;
import com.ymt.base.BaseBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveChatMessagePo;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.UserOnlineStatus;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*云通讯回事件处理
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_TimNotify extends BaseBean{
	private static TimNotifyBean timnotifyBean;
	private static TimNotifyCall timnotifyCall;
	private static TimNotifyReq timNotifyReq;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("云通讯回事件处理");
	}

	@Before
	public void caseUp() {
		timnotifyBean=new TimNotifyBean();
		timNotifyReq=new TimNotifyReq();
		initTimNotifyReq();
//		timnotifyCall=new TimNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("api/TimNotify");
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void initTimNotifyReq(){
		timNotifyReq.setCallbackCommand("State.StateChange");
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomCallService.ImSdkAppId);
		timNotifyReq.setTimNotifyType("StateChange");
		timNotifyReq.setContenttype("json");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_001() {
		Logger.start(true,"云通讯回事件处理成功,用户上线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_002() {
		Logger.start(true,"云通讯回事件处理成功,用户下线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			Info.setTo_Account("345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_003() {
		Logger.start(true,"云通讯回事件处理成功,用户更改在线状态");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			
			timNotifyReq.setClientIP(TestDataManager.getRandomIp());
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_004() {
		Logger.start(true,"未传用户id.云通讯回事件处理失败");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
//			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_005() {
		Logger.start(true,"sdkAppid错误.云通讯回事件处理失败");
		try {
			timNotifyReq.setSdkAppid("123");
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_006() {
		Logger.start(true,"callbackCommand不是待处理事件,不处理");
		try {
			timNotifyReq.setCallbackCommand("err");
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("err");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_007() {
		Logger.start(true,"云通讯回事件处理成功,global用户上线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("global-123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_008() {
		Logger.start(true,"云通讯回事件处理成功,global用户下线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			Info.setTo_Account("global-345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_009() {
		Logger.start(true,"云通讯回事件处理成功,global用户更改在线状态");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("global-1234");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			
			timNotifyReq.setClientIP(TestDataManager.getRandomIp());
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			uo = new LiveRoomWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	api/TimNotify?CallbackCommand=Group.CallbackAfterSendMsg&ClientIP=114.80.87.210&OptPlatform=iOS&SdkAppid=1400046801
//			{
//				"CallbackCommand" : "Group.CallbackAfterSendMsg",
//				"From_Account" : "20226434",
//				"GroupId" : "@TGS#aDNQD2RFB",
//				"MsgBody" : [{
//						"MsgContent" : {
//							"Data" : "{\"headPic\":\"http:\\/\\/pic1.ymatou.com\\/G01\\/M00\\/3E\\/6C\\/rBBlD1vFVtiAOtqmAABW6FtzAIo589_1_1_m.jpg\",\"userAction\":1,\"userId\":\"20226434\",\"nickName\":\"zhangyi_buyer001\"}",
//							"Desc" : "",
//							"Ext" : ""
//						},
//						"MsgType" : "TIMCustomElem"
//					}, {
//						"MsgContent" : {
//							"Text" : "{\"msg\":\"Gdhhdh\"}"
//						},
//						"MsgType" : "TIMTextElem"
//					}
//				],
//				"MsgSeq" : 11,
//				"MsgTime" : 1543991688,
//				"Type" : "AVChatRoom"
//			}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_010() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			String groupid=LiveRoomCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			String logoimg="http://www.ymatou.com/test2.jpg";
			JUserCallService.SetUserLogoCall(uid, logoimg);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+logoimg+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+regbean.getLoginId()+"\",\"buyerLevel\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(regbean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_011() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg-新增crown皇冠标示");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			String groupid=LiveRoomCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			String logoimg="http://www.ymatou.com/test2.jpg";
			JUserCallService.SetUserLogoCall(uid, logoimg);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+logoimg+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+regbean.getLoginId()+"\",\"buyerLevel\":\""+1+"\",\"crown\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(regbean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
			Logger.verifyEquals(1, msgs.get(0).getCrown(), "验证Crown");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_012() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg-新增newComer新人标示");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			String groupid=LiveRoomCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			String logoimg="http://www.ymatou.com/test2.jpg";
			JUserCallService.SetUserLogoCall(uid, logoimg);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+logoimg+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+regbean.getLoginId()+"\",\"buyerLevel\":\""+1+"\",\"newComer\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(regbean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
			Logger.verifyEquals(1, msgs.get(0).getNewComer(), "验证newComer");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_013() {
		Logger.start(true,"云通讯回事件处理成功,用户断线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Disconnect");
			Info.setReason("LinkClose");
			Info.setTo_Account("345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线 2断开
			Logger.verifyEquals(2, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_014() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackBeforeSendMsg-脏字前置处理");
		try {
			//脏字查 dirtywordconfig.action=0 的数据
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			String groupid=LiveRoomCallService.CreateGroup("CallbackBeforeSendMsg:"+TestDataManager.getRandomNum(5),createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			String logoimg="http://www.ymatou.com/test2.jpg";
			JUserCallService.SetUserLogoCall(uid, logoimg);
			
			timNotifyReq.setCallbackCommand("Group.CallbackBeforeSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackBeforeSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
//			"MsgBody": [ // 消息体，参见 TIMMessage 消息对象
//			             {
//			                 "MsgType": "TIMTextElem", // 文本
//			                 "MsgContent": {
//			                     "Text": "red packet"
//			                 }
//			             }
//			         ]
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
//			msgContent.setText("这个是脏字测试1");
			msgContent.setText("{\"msg\":\"这个是脏字测试08宪章\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+logoimg+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+regbean.getLoginId()+"\",\"buyerLevel\":\""+1+"\",\"newComer\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			timnotifyBean.setFromAccount("1");
//			timnotifyBean.setOperatorAccount("oautotest");
			timnotifyBean.setMsgBody(msgBody);
//			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("2", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			msgContent.setText("{\"msg\":\"通过\"}");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_015() {
		Logger.start(true,"云通讯回事件处理成功,计数器+1");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			
			timNotifyReq.setClientIP(TestDataManager.getRandomIp());
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			timnotifyCall.setData(timnotifyBean);
			
//			Integer counter = CounterCallService.getSingleValueByLiveId(liveroom.getId());
			timnotifyCall.callService();	
//			Integer counter1 = CounterCallService.getSingleValueByLiveId(liveroom.getId());
//			Logger.verifyEquals(counter+1, counter1, "添加商品之后，计数器+1");
						
			uo = new LiveRoomWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}